﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace Cotrobaie
{
    public class Misc
    {
        public static byte[] StrToByteArray(string str)
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            return encoding.GetBytes(str);
        }
        public static string ByteArrayToStr(byte[] array)
        {
            return System.Text.ASCIIEncoding.ASCII.GetString(array);
        }
        private static Random random = new Random();
        public static string GenerateRandomCode(int length)
        {
            string s = String.Empty;
            for (int i = 0; i < length; i++)
            {
                char temp = 'a';
                switch (random.Next(3))
                {
                    case 0: temp = (char)random.Next(49, 57); break;
                    case 1: temp = (char)random.Next(65, 90); break;
                    case 2: temp = (char)random.Next(97, 122); break;
                }
                s += temp.ToString();
            }
            return s;
        }
    }
}